
//
//  BACommentsVC.m
//  YunFu
//
//  Created by Bager on 2018/9/6.
//  Copyright © 2018年 yunfu. All rights reserved.
//

#import "BACommentsVC.h"

#import "XHStarRateView.h"
#import "LLTagViewUtils.h"
#import "PhotoBrowserVC.h"
#import "BACommentsCell.h"

@interface BACommentsVC ()<UITableViewDelegate,UITableViewDataSource>
{
    UIView *tagView;
}
@property (nonatomic, strong) UIView *scoreView;

@end

@implementation BACommentsVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self initTagView];
    
    [self createTable];
}

- (void)initTagView
{
    tagView = [[UIView alloc] initWithFrame:CGRectMake(kPublicMargin, 70, kScreenWidth - kPublicMargin * 2, 50)];
    
    LLTagViewUtils *tagViewUtils = [LLTagViewUtils new];
    [tagViewUtils setupCommonTagsInView:tagView tagTexts:@[@"味道赞 12",@"菜品好 22",@"价格实惠 16",@"服务热情 42",@"回头客 22",@"干净卫生 16",@"味道赞 12",@"菜品好 22",@"价格实惠 16",@"服务热情 42",@"回头客 22",@"干净卫生 16"] margin:6 tagHeight:20];
    
    tagViewUtils.commonTagStyle = ZYHTCommonTagStyleBorderTag;
    
    [tagViewUtils tagLabelOnClick:^(UITapGestureRecognizer *tapGes, UILabel *tagLabel) {
        
    }];
}

/**
 *  创建table
 */
- (void)createTable
{
    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kPublicNavHeight) style:UITableViewStyleGrouped];
    _table.delegate = self;
    _table.dataSource = self;
    _table.showsVerticalScrollIndicator = NO;
    //    _table.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_table];
    
    UIView *noLine = [[UIView alloc] initWithFrame:CGRectZero];
    _table.tableFooterView = noLine;
}

#pragma mark - table协议

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        return 80 + CGRectGetHeight(tagView.frame);
    }
    else
    {
        BACommentsCell *cell = [[BACommentsCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellIdentifiers"];
        NSLog(@"%f", [cell getHeightWithInfo:[CommentInfo new]]);
        return [cell getHeightWithInfo:[CommentInfo new]];
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 1;
    }
    else
    {
        return 20;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return [UIView new];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellIdentifier"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [cell addSubview:self.scoreView];
        
        return cell;
    }
    else
    {
        BACommentsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellIdentifiers"];
        if (!cell)
        {
            cell = [[BACommentsCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellIdentifiers"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        
        [cell setValueWithInfo:[CommentInfo new]];
        
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    PhotoBrowserVC *photo = [PhotoBrowserVC new];
//    photo.allowSelectVideo = YES;
//    DefineWeakSelf;
//    photo.selectImageBlock = ^(NSArray<UIImage *> *images, NSArray<PHAsset *> *assets, BOOL isOriginal) {
//
//        PHAsset *asset = assets[0];
//
//        if (asset.mediaType == PHAssetMediaTypeImage)
//        {
//
//        }
//        else if (asset.mediaType == PHAssetMediaTypeVideo)
//        {
//
//        }
//    };
//    [self.navigationController pushViewController:photo animated:NO];
}

- (UIView *)scoreView
{
    if (!_scoreView)
    {
        _scoreView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 300)];
        
        UILabel *scoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 2.0 - 60, 15, 50, 30)];
        scoreLabel.font = [UIFont systemFontOfSize:26];
        scoreLabel.text = @"4.3";
        scoreLabel.textColor = kPublicColorOrange;
        scoreLabel.textAlignment = NSTextAlignmentCenter;
        [_scoreView addSubview:scoreLabel];
        
        XHStarRateView *starView = [[XHStarRateView alloc] initWithFrame:CGRectMake(kScreenWidth / 2.0, 20, 70, 20)];
        starView.currentScore = 4.3;
        [_scoreView addSubview:starView];
        
        UILabel *scoreTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 2.0 - 60, 40, 120, 20)];
        scoreTextLabel.font = [UIFont systemFontOfSize:12];
        scoreTextLabel.text = @"综合评分";
        scoreTextLabel.textColor = [UIColor grayColor];
        scoreTextLabel.textAlignment = NSTextAlignmentCenter;
        [_scoreView addSubview:scoreTextLabel];

        [_scoreView addSubview:tagView];
    }
    return _scoreView;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (self.callBack)
    {
        self.callBack(scrollView);
    }
}



@end
